<template>
	<view class="sbody" v-if="informationList.informationId != undefined">
		<!-- 标题 -->
		<view class="info_title"><text>{{informationList.informationTitle}}</text></view>
		<!-- 发布时间 -->
		<uni-dateformat class="info_time" :date="informationList.createTime" format="yyyy/MM/dd hh:mm"></uni-dateformat>
		<!-- 文章内容 -->
		<rich-text class="info_detail" :nodes="informationList.informationDetails|formatRichText"></rich-text>
	</view>

	<view class="sbody" v-else-if="investmentList.investmentId != undefined">
		<!-- 标题 -->
		<view class="info_title"><text>{{investmentList.investmentTitle}}</text></view>
		<!-- 发布时间 -->
		<uni-dateformat class="info_time" :date="investmentList.createTime" format="yyyy/MM/dd hh:mm"></uni-dateformat>
		<!-- 文章内容 -->
		<rich-text class="info_detail" :nodes="investmentList.investmentDetails|formatRichText"></rich-text>
	</view>
</template>

<script>
	import {
		getInformation
	} from '../../common/js/api/information.js';
	import {
		getInvestment
	} from '../../common/js/api/investment.js';
	export default {
		data() {
			return {
				informationList: [],
				investmentList: []
			}
		},
		methods: {

		},
		onLoad(options) {
			var that = this
			//资讯动态id
			var informationId = options.informationId
			//招商引资id
			var investmentId = options.investmentId
			//根据informationId获取资讯动态详情

			if (informationId != undefined) {
				getInformation(informationId).then(res => {
					console.log(res)
					that.informationList = res.data
				})
			}
			if (investmentId != undefined) {
				getInvestment(investmentId).then(res => {
					that.investmentList = res.data
				})
			}
		},
		filters: {
			/**
			 * 处理富文本里的图片宽度自适应
			 * 1.查找img标签有无style属性，如果没有，加上style
			 * 2.所有标签style后追加 max-width:100% !important;
			 * 4.去掉<br/>标签
			 * @param html
			 * @returns {void|string|*}
			 */
			formatRichText(html) { //控制小程序中图片大小
				let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
					if (match.search(/style=/gi) == -1) {
						match = match
							.replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
							.replace(/<p>/ig, '<p style="">')
							.replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
							.replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
							.replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
							.replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
							.replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img style="width: 100%; border-radius: 8px;margin-bottom:10px;margin-top:15px" $1')
					}
					return match;
				});

				return newContent;
			}
		}

	}
</script>

<style>
	@import url("/static/font/iconfont.css");
</style>
<style>
	page {
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
	.sbody {
		width: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.info_title {
		width: 90%;
		margin-top: 20px;
		margin-bottom: 20px;
		display: flex;
		align-items: center;

	}

	text {
		width: 100%;
		font-family: PingFang SC;
		font-weight: bold;
		color: #000000;
		font-size: 18px;
	}

	.info_time {
		width: 90%;
		height: 32px;
		font-family: PingFang SC;
		color: #999999;
		font-size: 12px;
	}

	.info_detail {
		width: 90%;
		font-family: PingFang SC;
		color: #3a3a3a;
		font-size: 14px;
		margin-bottom: 50px;
	}
</style>
